package VNF_DelayLBA_large;

import java.io.File;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import com.net2plan.interfaces.networkDesign.NetPlan;

public class InitialNetPlan {
	public static final int numberOfAllVNFTypes = 8;
	public static void initialNetplan() {
		String ch = new String() ;
		ch = "/Users/shentianyu/Net2Plan-0.4.0/workspace/data/networkTopologies/US_Backbone.n2p";
		File f1 = new File(ch);
		NetPlan netplan = new NetPlan(f1);
		netplan.setAttribute("OccupiedSlot", "0");
		netplan.setAttribute("MFSI", "0");
		netplan.setAttribute("TotalUsedCPU", "0");
		netplan.setAttribute("AvgMFSI", "0");
		netplan.setAttribute("Numberofhops", "0");
		netplan.setAttribute("NumberofdeployedVNF", "0");
		netplan.setAttribute("BlockedRequest", "0");
		netplan.setAttribute("AverageCost", "0");
		netplan.setAttribute("TotalDelayTime", "0");
		netplan.setAttribute("TotalThreadTime", "0");
		
		/*
		 *随机选14个节点作为数据中心
		 */
		int len = 14; 
        int[] nums = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
        Set<Integer> set = new HashSet<Integer>();
        Random random = new Random();
        int i = 0;
        while (true) {
            i = random.nextInt(nums.length);
            set.add(nums[i]);
            if(set.size()>=len){
                break;
            }
        }
       
        //物理网络中的节点数
        int numberofnodes = netplan.getNumberOfNodes();
        for(int j=0;j<numberofnodes;j++) {
        	/*
        	 * 对于数据中心节点，用DataCenter来表征
        	 * 每个数据中心节点上VNF属性记载了铺设的VNF
        	 * 数字属性记录复用的次数
        	 * 便于最后计算延时或者铺设过程中做一些判断
        	 */
        	if(set.contains(j)) {
        		netplan.getNode(j).setAttribute("DataCenter", "1");
        		netplan.getNode(j).setAttribute("VNF", "0");
        		for(int vnfType = 1;vnfType<=numberOfAllVNFTypes;vnfType++) {
        			netplan.getNode(j).setAttribute(String.valueOf(vnfType), "0");
        		}
        	}
        	else {
        		netplan.getNode(j).setAttribute("DataCenter", "0");
        	}
        }  
        netplan = MyUtil.removeLayers(netplan);
        netplan = MyUtil.removeAllLayerDemand(netplan);
        netplan = MyUtil.substrateNetplanAttribute(netplan);
        
		File f_1= new File(ch);
		netplan.saveToFile(f_1);
	}
	
}
